package com.lj.dict.param;

import com.lj.common.utils.EnumUtils;
import com.lj.dict.entity.DictItem;
import com.lj.dict.enums.DictValueType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

/**
 * <p>
 * 字典项表 保存参数
 * </p>
 *
 * @author luojing
 * @since 2025-01-10 11:16:54
 */
@Data
@Schema(description = "字典项表 保存参数")
public class DictItemSaveParam {

    @Schema(description = "字典id")
    @NotNull(message = "字典id为必填")
    private Long dictId;

    @Schema(description = "字典标签")
    @NotBlank(message = "请填写字典标签")
    private String label;

    @Schema(description = "字典值")
    @NotBlank(message = "请填写字典值")
    private String value;

    @Schema(description = "字典值类型 这将决定获取字典项接口返回值的类型")
    @NotNull(message = "值类型为必须项")
    private Integer valueType;

    @Schema(description = "附加的信息")
    private String extendJson;

    @Schema(description = "排序")
    private Integer sort;

    public DictItem toEntity() {
        DictItem entity = new DictItem();
        entity.setDictId(dictId);
        entity.setLabel(label);
        entity.setValue(value);
        entity.setValueType(EnumUtils.getByValue(DictValueType.class, valueType));
        entity.setExtendJson(extendJson);
        entity.setSort(sort);
        return entity;
    }
}
